<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>Hello React!</title>
    <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
    <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>

<body>

    <div id="example"></div>
    <script type="text/babel">
        class Demo extends React.Component {
            // React.createRef() 调用后可以返回一个容器 该容器可以存储被ref所标识的节点 不过该容器专人专用
            myRef = React.createRef()

            showData = () => {
                alert(this.myRef.current.value)
            }

            showData2 = (event) => {
                alert(event.target.value)
            }
            render() {

                return (
                    <div>
                        
                        <input ref={this.myRef} type="text"/>
                        <button onClick={this.showData}>点我提示输入的数据</button>
                        <input onBlur={this.showData2} type="text" placeholder="失去焦点提示数据" />
                    </div>
                );
            }
        }

        ReactDOM.render(
            <Demo />,
            document.getElementById('example')
        );
    </script>

</body>

</html>